<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        时间复杂度 On
        空间复杂度 On
     -->
</head>
<body>
    <script>
        var isValid = function(s) {
            if (s.length % 2 == 1) {return false;}
            const stack = [];
            for (let i=0; i<s.length; i++) {
                if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
                    stack.push(s[i]);
                } else {
                    const t = stack[stack.length-1];
                    if (
                        (t == '(' && s[i] == ')') ||
                        (t == '[' && s[i] == ']') ||
                        (t == '{' && s[i] == '}')
                    ) {
                        stack.pop();
                    } else {
                        return false;
                    }
                }
            }
            return stack.length === 0;
        };
    </script>
</body>
</html>